<CFTRY>
	<CFSET tmpIdDet = GetEntry.DOCNUMBER>
	<CFSET tmpIdDet = GetEntry.DOCNUMBER>
	<CFMODULE TEMPLATE="#client.common_path#cfm_DBdateFormat.cfm" dateConvert="#DATEFORMAT(NOW(),'mm/dd/yyyy')#">
	<CFQUERY NAME="getEmployees" DATASOURCE="#client.subcompany_dsn#">
		SELECT * FROM SINMOVEMENTEMPS
		WHERE DOCNUMBER = '#tmpIdDet#'
		ORDER BY PERSONNELIDNO
	</CFQUERY>
	<CFQUERY NAME="getEffectDate" DATASOURCE="#table_dsn#">
		SELECT EFFECTIVEDATE,REASONCODE FROM SINMOVEMENTFORMS
		WHERE DOCNUMBER = '#tmpIdDet#'
	</CFQUERY>
	<CFQUERY NAME="updateAPPROVEDPOST" DATASOURCE="#table_dsn#">
		UPDATE SINMOVEMENTFORMS
		SET APPROVED = 'Y',
		APPROVEDBY = '#client.chapa#',
		DATEAPPROVED = #preserveSingleQuotes(sDate)#,
		POSTED = 'Y',
		POSTEDBY = '#client.chapa#',
		DATEPOSTED = #preserveSingleQuotes(sDate)#
		WHERE DOCNUMBER = '#tmpIdDet#'
	</CFQUERY>
	<CFMODULE TEMPLATE="#client.common_path#cfm_DBdateFormat.cfm" dateConvert="#getEffectDate.EFFECTIVEDATE#">
	<CFSET sEffctvdate = dateResult>
	<CFIF DATEFORMAT(NOW()) GTE DATEFORMAT(getEffectDate.EFFECTIVEDATE)>
		<CFSET PostOtherItems = true>
	<CFELSE>
		<CFSET PostOtherItems = false>
	</CFIF>
	<CFMODULE TEMPLATE="#client.common_path#cfm_DBdateFormat.cfm" dateConvert="#DATEFORMAT(NOW(),'mm/dd/yyyy')#">
	<CFSET sDate = dateResult>

	<CFOUTPUT QUERY="getEmployees">
		<CFSET currID = PERSONNELIDNO>
		<CFQUERY NAME="getGuid" DATASOURCE="#client.company_dsn#">
			SELECT GUID FROM CMFPA WHERE PERSONNELIDNO = '#currID#'
		</CFQUERY>

		<CFQUERY NAME="getItemPerCandidate" DATASOURCE="#client.subcompany_dsn#">
			SELECT * FROM SINMOVEMENTDELTA
			WHERE DOCNUMBER = '#tmpIdDet#' AND PERSONNELIDNO = '#currID#' AND (POSTED <> 'Y' OR POSTED IS NULL)
				AND EFFECTIVEDATE <= #preserveSingleQuotes(sDate)#
			ORDER BY ITEMCODE
		</CFQUERY>
		<!------>
		<CFLOOP QUERY="getItemPerCandidate">
			<CFIF getItemPerCandidate.ITEMORIGINALVALUE NEQ getItemPerCandidate.ITEMNEWVALUE>
				<CFMODULE TEMPLATE="#client.common_path#cfm_moveitems.cfm"
					primaryKey="PERSONNELIDNO"
					pkVALUE="#currID#"
					itemCode="#getItemPerCandidate.ITEMCODE#"
					itemValue="#getItemPerCandidate.ITEMNEWVALUE#"
					POSTTABLE="SINMOVEMENTDELTA"
					POSTPRIMARY = "DOCNUMBER,ITEMCODE,PERSONNELIDNO"
					POSTPRIMARYVAL="#tmpIdDet#,#getItemPerCandidate.ITEMCODE#,#currID#"
					POSTDSN="#client.subcompany_dsn#"
					REASONCODE="#getItemPerCandidate.REASONCODE#"
					MONTHLY="#getItemPerCandidate.MONTHLY#"
					WITHRETRO="#getItemPerCandidate.WITHRETRO#"
					RETROSTARTDATE="#getItemPerCandidate.RETROSTARTDATE#"
					RETROENDDATE="#getItemPerCandidate.RETROENDDATE#"
					DOCNUMBER="#tmpIdDet#"
					EFFECTIVEDATE="#getItemPerCandidate.EFFECTIVEDATE#"
					GLOBAL_DSN = "#client.global_dsn#"
					COMPANY_DSN = "#client.company_dsn#"
					SUBCOMPANY_DSN = "#client.subcompany_dsn#"
					DBMS = "#client.dbms#"
					>
				<CFMODULE TEMPLATE="#client.common_path#cfm_movehist.cfm"
					ITEMCODE = "#getItemPerCandidate.ITEMCODE#"
					ORIGINALVALUE = "#getItemPerCandidate.ITEMORIGINALVALUE#"
					NEWVALUE = "#getItemPerCandidate.ITEMNEWVALUE#"
					EFFECTIVEDATE = "#getItemPerCandidate.EFFECTIVEDATE#"
					REASONCODE = "#getItemPerCandidate.REASONCODE#"
					ORIGINALDESC = "null"
					NEWDESC = "null"
					GUID = "#getGuid.GUID#"
					PERSONNELIDNO = "#currID#"
					GLOBAL_DSN = "#client.global_dsn#"
					COMPANY_DSN = "#client.company_dsn#"
					SUBCOMPANY_DSN = "#client.subcompany_dsn#"
					DBMS = "#client.dbms#"
					>
				</cfif>
		</CFLOOP>
		<CFMODULE TEMPLATE="#client.common_path#cfm_movecasfilterfields.cfm"
			primaryKey="PERSONNELIDNO"
			pkVALUE="#currID#"
			itemCodes="#quotedValueList(getItemPerCandidate.ITEMCODE)#"
			DBMS = "#client.dbms#"
			GLOBAL_DSN = "#client.global_dsn#"
			>
	</CFOUTPUT>

	<CFQUERY NAME="qryIsEffective" DATASOURCE="#client.subcompany_dsn#">
		SELECT
			DOCNUMBER
		FROM
			SINMOVEMENTFORMS WHERE DOCNUMBER = '#tmpIdDet#' AND EFFECTIVEDATE <= #preserveSingleQuotes(sDate)#
	</CFQUERY>

	<CFSET sPosted = "Y">
	<CFSET sPostedby = client.chapa>
	<CFSET sDatePosted = sDate>
	<CFIF qryIsEffective.Recordcount EQ 0>
		<CFSET sPosted = "N">
		<CFSET sPostedby = "">
		<CFSET sDatePosted = "">
	</CFIF>
	<CFQUERY NAME="updateAPPROVEDPOST" DATASOURCE="#client.subcompany_dsn#">
		UPDATE SINMOVEMENTFORMS
		SET APPROVED = 'Y',
		APPROVEDBY = '#client.chapa#',
		DATEAPPROVED = #preserveSingleQuotes(sDate)#,
		POSTED = '#sPosted#',
		POSTEDBY = '#sPostedby#',
		DATEPOSTED = #preserveSingleQuotes(sDatePosted)#
		WHERE DOCNUMBER = '#tmpIdDet#'
	</CFQUERY>
	<CFMODULE TEMPLATE="#client.common_path#postIntercompany.cfm"
	MOVEMENTID="#tmpIdDet#"
	GLOBAL_DSN="#client.global_dsn#"
	COMPANY_DSN="#client.company_dsn#"
	SUBCOMPANY_DSN="#client.subcompany_dsn#"
	DBMS="#client.DBMS#">
<CFCATCH TYPE="ANY">
	<CFSET sWarn = #CFCATCH.message# & #CFCATCH.DETAIL#>
</CFCATCH>
</CFTRY>
